var e = require;
var t = module;
var o = exports;
var Adv_skd=require("./Adv_skd");
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("NotifyEventType"),
    a = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("AudioManager"),
    s = e("ModuleUI"),
    l = e("Game"),
    c = e("RoleSoldierInfo"),
    d = e("GuideMaskViewUI"),
    h = e("UIManager"),
    _ = e("ShopViewUI"),
    u = e("sdkConfig"),
    p = e("AD"),
    m = e("Toast"),
    f = e("ChooseHeroSkillInfo"),
    g = e("choose_player_info"),
    v = e("choose_role_item"),
    y = e("GetZsViewUI"),
    S = cc._decorator,
    I = S.ccclass,
    w = S.property,
    N = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.role_item = null),
                (t.all_role_type_top = null),
                (t.all_role_list_view = null),
                (t.near_role_type_top = null),
                (t.near_role_list_view = null),
                (t.far_role_type_top = null),
                (t.far_role_list_view = null),
                (t.role_ske_node = null),
                (t.role_name_label = null),
                (t.sure_btn_node = null),
                (t.get_btn_node = null),
                (t.left_player_view = null),
                (t.hero_skill_info_node = null),
                (t.hero_dower_node = null),
                (t.player_skill_ndoe = null),
                (t.right_hero_list_view = null),
                (t.right_skill_view = null),
                (t.count_down_label = null),
                (t.native_icon_node = null),
                (t.main_role_index = 0),
                (t.choose_player_node = null),
                (t.count_down = 15),
                t
            );
        }
        return (
            __extends(t, e),

            (t.prototype.onDisable = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();

            }),

            (t.prototype.initView = function () {

                Adv_skd.default.instance.hideBannerAd();
                Adv_skd.default.instance.hideGridAdLeft();
                Adv_skd.default.instance.hideGridAdRight();
                Adv_skd.default.instance.hideGridAdTop();
                Adv_skd.default.instance.hideGridAdLeftOne();
                Adv_skd.default.instance.hideGridAdRightOne();
                Adv_skd.default.instance.hideGridAdButtom();
                Adv_skd.default.instance.showGridAdLeft();
                Adv_skd.default.instance.showGridAdRight();
                Adv_skd.default.instance.showGridAdTop();
                Adv_skd.default.instance.showBannerAd();
                Adv_skd.default.instance.showInterstitialAd();

                e.prototype.initView.call(this),
                    r.default.getInstance().setMusicVolume(0.2),
                    r.default.getInstance().playFx("choose_hero"),
                    a.GlobalParams.gameShock.value && p.default.getInstance().vibrateShort(),
                    (this.right_hero_list_view.active = !0),
                    (this.hero_dower_node.active = !1),
                    (this.player_skill_ndoe.active = !1),
                    (this.right_skill_view.active = !1),
                    (this.choose_player_node = null),
                    this.showRoleListInfo(),
                    this.showPlayerInfo(),
                    (this.main_role_index = a.GlobalParams.GameHeroIndex.indexOf(
                        a.GlobalParams.playerSkinInfo.value.use[0]
                    )),
                    this.showRoleSke(),
                    a.GlobalParams.PlayGuideMode &&
                        cc
                            .find("UIManager")
                            .getComponent(h.default)
                            .showPopup("GuideMaskViewUI", function (e) {
                                e.getComponent(d.default).showGuideInfoView(1);
                            });
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_CHOOSE_ROLE_INDEX_INFO, this.showChooseRole, this);
            }),
            (t.prototype.showRoleListInfo = function () {
                for (var e = c.default.Role_info, t = 0; t < a.GlobalParams.GameHeroIndex.length; t++) {
                    var o = a.GlobalParams.GameHeroIndex[t],
                        n = cc.instantiate(this.role_item),
                        i = cc.instantiate(this.role_item);
                    (n.active = !0),
                        (i.active = !0),
                        n.getComponent(v.default).showRoleInfo(e[o], o),
                        i.getComponent(v.default).showRoleInfo(e[o], o),
                        n.setParent(this.all_role_list_view),
                        i.setParent(0 == e[o].C_type ? this.near_role_list_view : this.far_role_list_view);
                }
                u.default.platform == u.EPlatform.No_AD ||
                    p.default.getInstance().getGameTestVersion() ||
                    ((this.native_icon_node.active = !0), this.native_icon_node.setParent(this.all_role_list_view));
            }),
            (t.prototype.OnClick = function (t) {
                e.prototype.OnClick.call(this, t);
                var o = t.node;
                switch (o.name) {
                    case "back_btn":
                        if (a.GlobalParams.PlayGuideMode) return void m.default.showNewToast("引导中请勿操作");
                        this.emitEvent(n.default.SEND_BOX_PORTAL_INFO, !0),
                            (a.GlobalParams.MathcTimeInfo.open = !0),
                            r.default.getInstance().setMusicVolume(0.5),
                            this.uiManager.showCoinAndZs(!0),
                            this.node.destroy();
                        break;
                    case "all_role_type_top":
                        (this.all_role_list_view.active = !this.all_role_list_view.active),
                            (o.getChildByName("image_xzyx_jt").scaleY *= -1);
                        break;
                    case "near_role_type_top":
                        (this.near_role_list_view.active = !this.near_role_list_view.active),
                            (o.getChildByName("image_xzyx_jt").scaleY *= -1);
                        break;
                    case "far_role_type_top":
                        (this.far_role_list_view.active = !this.far_role_list_view.active),
                            (o.getChildByName("image_xzyx_jt").scaleY *= -1);
                        break;
                    case "right_btn":
                        this.main_role_index++,
                            (this.main_role_index = this.main_role_index > 12 ? 0 : this.main_role_index),
                            this.showRoleSke();
                        break;
                    case "left_btn":
                        this.main_role_index--,
                            (this.main_role_index = this.main_role_index < 0 ? 12 : this.main_role_index),
                            this.showRoleSke();
                        break;
                    case "sure_btn":
                        a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].role_id =
                            a.GlobalParams.GameHeroIndex[this.main_role_index];
                        var i = a.GlobalParams.playerSkinInfo.value;
                        (i.use[0] = a.GlobalParams.GameHeroIndex[this.main_role_index]),
                            (a.GlobalParams.playerSkinInfo.value = i),
                            this.choose_player_node.getComponent(g.default).showPlayerInfo(a.GlobalParams.MatchMyIndex),
                            (this.right_hero_list_view.active = !1),
                            (this.hero_dower_node.active = !0),
                            (this.player_skill_ndoe.active = !0),
                            (this.right_skill_view.active = !0),
                            (this.count_down = 15),
                            a.GlobalParams.PlayGuideMode
                                ? (cc
                                      .find("UIManager")
                                      .getComponent(h.default)
                                      .showPopup("GuideMaskViewUI", function (e) {
                                          e.getComponent(d.default).showGuideInfoView(2);
                                      }),
                                  (this.count_down_label.string = "等待开始(" + this.count_down + ")"))
                                : this.loadFightPrefabs();
                        break;
                    case "get_btn":
                        this.buyRoleSke();
                }
            }),
            (t.prototype.showRoleSke = function () {
                var e = this,
                    t = a.GlobalParams.playerSkinInfo.value;
                (this.sure_btn_node.active =
                    -1 != t.have.hero.indexOf(a.GlobalParams.GameHeroIndex[this.main_role_index])),
                    (this.get_btn_node.active =
                        -1 == t.have.hero.indexOf(a.GlobalParams.GameHeroIndex[this.main_role_index])),
                    this.uiManager.getRoleSkele(a.GlobalParams.GameHeroIndex[this.main_role_index], function (t) {
                        (e.role_ske_node.skeletonData = t), e.role_ske_node.setAnimation(0, "battle_idle", !0);
                    }),
                    (this.role_name_label.string =
                        "" + c.default.Role_info[a.GlobalParams.GameHeroIndex[this.main_role_index]].C_Name),
                    this.emitEvent(
                        n.default.SEND_CHOOSE_ROLE_INDEX_INFO,
                        a.GlobalParams.GameHeroIndex[this.main_role_index]
                    ),
                    this.hero_skill_info_node
                        .getComponent(f.default)
                        .getSkillInfo(a.GlobalParams.GameHeroIndex[this.main_role_index]);
            }),
            (t.prototype.showChooseRole = function (e, t) {
                var o = this;
                this.main_role_index = a.GlobalParams.GameHeroIndex.indexOf(t);
                var n = a.GlobalParams.playerSkinInfo.value;
                (this.sure_btn_node.active =
                    -1 != n.have.hero.indexOf(a.GlobalParams.GameHeroIndex[this.main_role_index])),
                    (this.get_btn_node.active =
                        -1 == n.have.hero.indexOf(a.GlobalParams.GameHeroIndex[this.main_role_index]));
                var i = l.default.shop_role_info[a.GlobalParams.GameHeroIndex[this.main_role_index]];
                this.uiManager.getRoleSkele(i.id, function (e) {
                    (o.role_ske_node.skeletonData = e), o.role_ske_node.setAnimation(0, "battle_idle", !0);
                }),
                    (this.role_name_label.string = "" + c.default.Role_info[i.id].C_Name),
                    this.showRoleSkeBtn(),
                    this.hero_skill_info_node
                        .getComponent(f.default)
                        .getSkillInfo(a.GlobalParams.GameHeroIndex[this.main_role_index]);
            }),
            (t.prototype.showPlayerInfo = function () {
                for (var e = 0; e < a.GlobalParams.MatchGamePlayer.length; e++)
                    if (e % 2 == a.GlobalParams.MatchMyIndex % 2) {
                        var t = Math.floor(e / 2);
                        this.left_player_view.children[t].getComponent(g.default).showChoosePlayerInfo(e),
                            e == a.GlobalParams.MatchMyIndex &&
                                (this.choose_player_node = this.left_player_view.children[t]);
                    }
            }),
            (t.prototype.showCountDown = function () {
                var e = this;
                (this.count_down_label.string = "等待开始(" + this.count_down + ")"),
                    this.count_down <= 0
                        ? this.uiManager.showPopup("LoadingViewUI")
                        : this.scheduleOnce(function () {
                              e.count_down--, e.showCountDown();
                          }, 1);
            }),
            (t.prototype.loadFightPrefabs = function () {
                this.showCountDown(),
                    this.emitEvent(n.default.SEND_COCOS_ANALYTICS, {
                        name: "事件一",
                        info: "使用英雄ID:" + a.GlobalParams.GameHeroIndex[this.main_role_index]
                    }),
                    i.default.getInstance().loadFightPrefabs("fight");
            }),
            (t.prototype.showRoleSkeBtn = function () {
                var e = l.default.shop_role_info[a.GlobalParams.GameHeroIndex[this.main_role_index]];
                (this.get_btn_node.children[6].active = a.GlobalParams.playerSkinInfo.value.have.taste_card > 0),
                    (this.get_btn_node.children[0].active = 0 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[1].active = 1 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[4].active = 2 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[5].active = 3 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[3].active = 4 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[0].children[1].getComponent(cc.Label).string =
                        this.get_btn_node.children[1].children[1].getComponent(cc.Label).string =
                            "" + e.num * e.discount),
                    (this.get_btn_node.children[2].active = 1 != e.discount && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[2].getComponent(cc.Label).string = "" + e.num);
            }),
            (t.prototype.buyRoleSke = function () {
                var e = this,
                    t = l.default.shop_role_info[a.GlobalParams.GameHeroIndex[this.main_role_index]],
                    o = function () {
                        var o = a.GlobalParams.playerSkinInfo.value;
                        (o.use[0] = t.id),
                            o.have.hero.push(t.id),
                            (a.GlobalParams.playerSkinInfo.value = o),
                            cc.find("UIManager").getComponent(h.default).showPopup("ObtainHeroTipView"),
                            e.emitEvent(n.default.SEND_UPDATE_CHOOSE_HERO_LIST),
                            e.showRoleSke();
                    },
                    i = a.GlobalParams.PlayerInfo.value;
                if (this.get_btn_node.children[0].active) {
                    var s = t.num * t.discount;
                    i.coin >= s
                        ? (cc.find("UIManager").getComponent(h.default).consumeCoinAndZs(0, s), o())
                        : cc
                              .find("UIManager")
                              .getComponent(h.default)
                              .showPopup("ShopViewUI", function (e) {
                                  e.getComponent(_.default).showShopTypeInfo("shop_coin_btn");
                              });
                } else if (this.get_btn_node.children[1].active) {
                    var c = t.num * t.discount;
                    i.zs >= c
                        ? (cc.find("UIManager").getComponent(h.default).consumeCoinAndZs(1, c), o())
                        : cc
                              .find("UIManager")
                              .getComponent(h.default)
                              .showPopup("GetZsViewUI", function (e) {
                                  e.getComponent(y.default).showPopupInfoView(0);
                              });
                } else if (this.get_btn_node.children[3].active)
                    p.default.getInstance().showVideo(function (e) {
                        r.default.playGameBGM(), e == p.ResultEnum.Success && o();
                    });
                else if (this.get_btn_node.children[4].active) this.uiManager.showPopup("SigninViewUI");
                else if (this.get_btn_node.children[5].active) this.uiManager.showPopup("LuckyBoxViewUI");
                else if (this.get_btn_node.children[6].active) {
                    var d = a.GlobalParams.playerSkinInfo.value;
                    (d.have.taste_card -= 1),
                        (a.GlobalParams.playerSkinInfo.value = d),
                        this.emitEvent(n.default.UPDATE_HAVE_TASTE_CARD_NUMBER),
                        (a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].role_id =
                            a.GlobalParams.GameHeroIndex[this.main_role_index]),
                        this.choose_player_node.getComponent(g.default).showPlayerInfo(a.GlobalParams.MatchMyIndex),
                        (this.right_hero_list_view.active = !1),
                        (this.hero_dower_node.active = !0),
                        (this.player_skill_ndoe.active = !0),
                        (this.right_skill_view.active = !0),
                        (this.count_down = 15),
                        this.loadFightPrefabs();
                }
            }),
            __decorate([w(cc.Node)], t.prototype, "role_item", void 0),
            __decorate([w(cc.Node)], t.prototype, "all_role_type_top", void 0),
            __decorate([w(cc.Node)], t.prototype, "all_role_list_view", void 0),
            __decorate([w(cc.Node)], t.prototype, "near_role_type_top", void 0),
            __decorate([w(cc.Node)], t.prototype, "near_role_list_view", void 0),
            __decorate([w(cc.Node)], t.prototype, "far_role_type_top", void 0),
            __decorate([w(cc.Node)], t.prototype, "far_role_list_view", void 0),
            __decorate([w(sp.Skeleton)], t.prototype, "role_ske_node", void 0),
            __decorate([w(cc.Label)], t.prototype, "role_name_label", void 0),
            __decorate([w(cc.Node)], t.prototype, "sure_btn_node", void 0),
            __decorate([w(cc.Node)], t.prototype, "get_btn_node", void 0),
            __decorate([w(cc.Node)], t.prototype, "left_player_view", void 0),
            __decorate([w(cc.Node)], t.prototype, "hero_skill_info_node", void 0),
            __decorate([w(cc.Node)], t.prototype, "hero_dower_node", void 0),
            __decorate([w(cc.Node)], t.prototype, "player_skill_ndoe", void 0),
            __decorate([w(cc.Node)], t.prototype, "right_hero_list_view", void 0),
            __decorate([w(cc.Node)], t.prototype, "right_skill_view", void 0),
            __decorate([w(cc.Label)], t.prototype, "count_down_label", void 0),
            __decorate([w(cc.Node)], t.prototype, "native_icon_node", void 0),
            __decorate([I], t)
        );
    })(s.default);
o.default = N;
